/**
 *******************************************************************************
 *  FileName  : reset.c
 *  Date      : 2023-4-21
 *  Author    : GaoQiu
 *  Copyright : (C)All rights reserved.
 *******************************************************************************
 *
 * The information contained herein is confidential and proprietary property of
 * GaoQiu and is available under the terms of Commercial License Agreement
 * between GaoQiu and the licensee in separate contract or the terms described
 * here-in.
 *
 * This heading MUST NOT be removed from this file.
 *
 * Licensees are granted free, non-transferable use of the information in this
 * file under Mutual Non-Disclosure Agreement. NO WARRENTY of ANY KIND is provided.
 *
 *******************************************************************************
 */
#include "utils/defs_types.h"
#include "utils/utils.h"

#include "bsp/bsp.h"
#include "platform/platform.h"

#if CFG_OS_EN
#include "FreeRTOS.h"
#include "task.h"

TaskHandle_t mainTaskHandle;

void init(void *p)
{
	extern int main(void);
	main();

	//while(1){vTaskDelay(pdMS_TO_TICKS(200));}
	vTaskDelete(mainTaskHandle);
}
#endif

void reset_handler(void)
{
	//sleep_us(500*1000);

#if CFG_OS_EN
	do_initcall();

    NVIC_SetPriority(LL_IRQn,     0);

  #ifdef IP_108
    NVIC_SetPriority(TRIM_IRQn,   1);
  #elif defined(IP_107)
    NVIC_SetPriority(TMR2_IRQn,   1);
  #endif

    // OS
    NVIC_SetPriority(PendSV_IRQn, 2);
    NVIC_SetPriority(SysTick_IRQn,2);

	CLK_AHBPeriphClockCmd(CLK_AHBPeriph_SYSTICK, ENABLE);
	NVIC_EnableIRQ(SysTick_IRQn);

    xTaskCreate(init, "init", CFG_OS_MAIN_TASK_STACK_SIZE, NULL, CFG_OS_MAIN_TASK_PRIORITY, &mainTaskHandle);

	/* Start the kernel.  From here on, only tasks and interrupts will run. */
	vTaskStartScheduler();
#else
	extern int main(void);
	main();
#endif

	while(1);
}
